import {
    userActivityService,
    userActivityTypeService,
    userActivityByIdService,
    userActivityRegListService,
    userActivityRegByUserIdService,
    getVolunteerInfoService,
    queryPageVolunteerActivityService,
} from "@/api/front/common";

const state = {
    activityList: [],
    total: 0,
    activityRegRespData: [],

    activity:{},
    activityType: [],

    activityRegList: [],
    totalReg: 0,

    userActivityRegList: [],
    volunteerActivityRegList: [],
    
    volunteerActivityList: [],
    volunteerActivityTotal:0,

};
const mutations = {
    // 分页查询活动信息
    userActivityListMutations(state, param) {
        state.activityList = param.data;
        state.total = param.total;
    },
    
    // 活动类别
    userActivityTypeMutations(state, param) {
        state.activityType = param.data;
        state.total = param.total;
    },

    // 活动详情
    userActivityByIdMutations(state, param) {
        state.activity = param.data;
        state.total = param.total;
    },


    // 用户报名活动列表
    pageQueryActivityRegMutations(state, param) {
        state.activityRegList = param.data;
        state.totalReg = param.total;
    },

    userActivityByUserIdMutations(state, param) {
        state.userActivityRegList = param.data;
    },

    volunteerActivityByUserIdMutations(state, param) {
        state.volunteerActivityRegList = param.data;
    },

    queryPageVolunteerActivityMutations(state, param) {
        state.volunteerActivityList = param.data;
        state.volunteerActivityTotal = param.total;
    },
};
const actions = {
    // 分页查询活动信息
    async userActivityListActions(context, page) {
        await userActivityService(page).then(resp => {
            if (!resp) return;
            console.log('activity-->', resp.data);
            context.commit('userActivityListMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // 活动类别
    async userActivityTypeActions(context) {
        await userActivityTypeService().then(resp => {
            if (!resp) return;
            console.log('activity-->', resp.data);
            context.commit('userActivityTypeMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // 活动类别
    async userActivityByIdActions(context,id) {
        await userActivityByIdService(id).then(resp => {
            if (!resp) return;
            console.log('activity-->', resp.data);
            context.commit('userActivityByIdMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // --- 活动报名信息
    // 分页查询活动报名信息
    async pageQueryactivityRegListActions(context, page) {
        await userActivityRegListService(page).then(resp => {
            if (!resp) return;
            console.log('activityReg-->', resp.data);
            context.commit('pageQueryActivityRegMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    async userActivityByUserIdActions(context) {
        await userActivityRegByUserIdService().then(resp => {
            if (!resp) return;
            console.log('activity123-->', resp.data);
            context.commit('userActivityByUserIdMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    async volunteerActivityByUserIdActions(context) {
        await getVolunteerInfoService().then(resp => {
            if (!resp) return;
            console.log('activityv-->', resp.data);
            context.commit('volunteerActivityByUserIdMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    async queryPageVolunteerActivityActions(context,page) {
        await queryPageVolunteerActivityService(page).then(resp => {
            if (!resp) return;
            console.log('activityvvv123-->', resp.data);
            context.commit('queryPageVolunteerActivityMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}